<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 600px;height:400px;"></div>

	<!-- 引入 ECharts 文件 -->
    <script src="${path}/static/lib/echarts.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/myUtil.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function(){
			// 基于准备好的dom，初始化echarts实例
		       var myChart = echarts.init(document.getElementById('main'));
		
			   $.ajax({
				   url: "${path}/category/getCategoryProductCount.action",
	    	       type: "post",
	    	       dataType: "json",
	    	       success:function(jsonObj){
	    	    	   if(jsonObj.code === myUtil.SUCCESS){
	    	    		   var data = jsonObj.data;
	    	    		   // List<CategoryCount> list;
	    	    		   var xArray = new Array();
	    	    		   var yArray = new Array();
	    	    		   $(data).each(function(){
	    	    			   xArray.push(this.name);
	    	    			   yArray.push(this.count);
	    	    		   })
	    	    		   // 指定图表的配置项和数据
		    		       var option = {
		    		           title: {
		    		               text: '分类商品数量'
		    		           },
		    		           tooltip: {},
		    		           legend: {
		    		               data:['数量']
		    		           },
		    		           xAxis: {
		    		               data: xArray
		    		           },
		    		           yAxis: {},
		    		           series: [{
		    		               name: '数量',
		    		               type: 'bar',
		    		               itemStyle: {
		    		            	  normal: {
	    		            	           barBorderRadius:[6, 6, 6, 6],// 设置柱状图 圆角
	    		            	           color: function(params) {// 柱状图设置不同颜色
	    		            	           var colorList = ['#65b5c2', '#ff54a6','#1dc499','#177bbb', '#e35645','#ffbe05','#3ddcde'];
	    		            	           return colorList[params.dataIndex]
		    		            	       }
		    		            	   }
		    		              },
		    		               data: yArray
		    		           }]
		    		       };
		    		
		    		       // 使用刚指定的配置项和数据显示图表。
		    		       myChart.setOption(option);
	    	    	   }
	    	       }
			   });
		});
	       
	 </script>
	
</body>
</html>